/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nominalitzacions.domain;

import java.io.FileNotFoundException;
import java.io.IOException;
import nominalitzacions.persistance.LanguageDataManagerController;


/**
 *
 * @author genis
 */
public class LanguageDomainController {

    Languages languages;
    LanguageDataManagerController LDMC;

    public LanguageDomainController() throws FileNotFoundException {
        LDMC = new LanguageDataManagerController();
        languages = new Languages();
        iniLanguages();
    }

    public String [] getLanguageNames() {
        return languages.getLanguageNames();
    }

    public boolean containsLang(String langName) {
        if (langName == null) {
            return false;
        } else {
            String [] langs = languages.getLanguageNames();
            for (int i = 0; i < langs.length; ++i) {
                if (langName.equals(langs[i])) {
                    return true;
                }
            }
            return false;
        }
    }
    
    public void addLanguage(String langName, String infPath, String irrPath,
                            String nounsPath, String corpPath) 
                            throws IOException {
        Language lang = new Language(langName, infPath, irrPath, nounsPath,
                                     corpPath);
        languages.addLanguage(lang);
        LDMC.saveLanguage(langName, irrPath, infPath, nounsPath, corpPath);

    }

    public void deleteLanguage(String langName) {
        languages.deleteLanguage(langName);
        LDMC.deleteLanguage(langName);
    }
    
    public String getInfPath(String langName) {
        return languages.getLanguage(langName).getDicoInfPath();
    }

    public String getIrrPath(String langName) {
        return languages.getLanguage(langName).getDicoIrregPath();
    }

    public String getNounsPath(String langName) {
        return languages.getLanguage(langName).getDicoNamePath();
    }

    public String getCorpPath(String langName) {
        return languages.getLanguage(langName).getCorpusPath();
    }

    public Language getLanguage(String langName) {
        return languages.getLanguage(langName);
    }

    /*public void setActiveLanguage(String lang) {
        String [] ls = languages.getLanguageNames();
        for (int i = 0; i < ls.length; ++i) {
            if (!ls[i].equals(lang)) {
                languages.getLanguage(ls[i]).setState(new InactiveLanguage());
            } else {
                languages.getLanguage(lang).setState(new ActiveLanguage());
            }
        }
    }*/

    private void iniLanguages() throws FileNotFoundException {
        Language [] ls = LDMC.loadAllLanguages();
        for (int i = 0; i < ls.length; ++i) {
            languages.addLanguage(ls[i]);
        }
    }
}
